<?php 
	$contents_ranking = json_decode( file_get_contents(SERVER_WEB.'db/contents_ranking_db.php?limit=3&user_id='.$user_profile['id']) );
	$authors_ranking = json_decode( file_get_contents(SERVER_WEB.'db/authors_ranking_db.php?limit=3&user_id='.$user_profile['id']) );
?>

<!-- Main -->
<div id="main">
	<div class="down-options" id="down-options">
		
		<!-- Cols -->
		<div class="two-cols">
			<div class="cl">&nbsp;</div>
			
			<!-- Col -->
			<div class="col" style="margin-left: 85px;">
				<h3><?php echo BEST_CONTENTS; ?></h3>

				<?php
				for ($i = 0; $i < count($contents_ranking); $i++) {
					echo "<hr/>";
					
					echo "<div>";
					echo "<table class=\"best-content\" border=\"0px\" cellpadding=\"0px\" cellspacing=\"0px\">";
							echo "<tr>";
								echo "<td valign=\"top\" class=\"ranking-number\" >".$contents_ranking[$i]->rank."</td>";
								echo "<td id=\"down-option-content-td-".$i."\" rowspan=\"2\" valign=\"middle\" >";
									echo $contents_ranking[$i]->content;
								echo "</td>";
								echo "<td></td>";
							echo "</tr>";
							echo "<tr>";
								echo "<td></td>";
								echo "<td></td>";
							echo "</tr>";
							echo "<tr>";
								echo "<td></td>";
								echo "<td align=\"right\" class=\"author-name\"> ";
									echo $contents_ranking[$i]->first_name.' '.$contents_ranking[$i]->last_name;
								echo "</td>";
								echo "<td align=\"right\" height=\"5px\" width=\"37px\">";
									echo "<a id=\"see-content-".$i."\" class=\"more\" href=\"".CONTENTS_URL."?content_id=".$contents_ranking[$i]->content_id."&coming_from=".$current_file."\">".SEE."</a>";
								echo "</td>";
							echo "</tr>";
						echo "</table>";
					echo "</div>";
				}
				?>
				
				<hr/>
				
				<div style="text-align: right; margin-top: 5px;">
					<a id="see-best-contents" class="more" href="bestContents.php?category_id=<?php echo $category_id; ?>&coming_from=<?php echo $current_file; ?>"><?php echo SEE_BEST_CONTENTS;?></a>
				</div>
				
			</div>
			<!-- End Col -->
			
			<!-- Col -->
			<div class="col">
				<h3><?php echo BEST_AUTHORS; ?></h3>

				<?php
				for ($i = 0; $i < count($authors_ranking); $i++) {

					echo "<hr/>";

					echo "<div>	";
						echo "<table border=\"0px\" class=\"best-content\" cellpadding=\"0px\" cellspacing=\"0px\">";
							echo "<tr>";
								echo "<td valign=\"top\" class=\"ranking-number\" >".$authors_ranking[$i]->rank."</td>";
								echo "<td rowspan=\"2\" valign=\"middle\" >";
									echo "<img src=\"https://graph.facebook.com/".$authors_ranking[$i]->user_id."/picture\" />";
								echo "</td>";
								echo "<td rowspan=\"2\" valign=\"middle\" class=\"author-name-list\">";
									echo $authors_ranking[$i]->first_name.' '.$authors_ranking[$i]->last_name;
								echo "</td>";
							echo "</tr>";
							echo "<tr>";
								echo "<td></td>";
							echo "</tr>";
							echo "<tr>";
								echo "<td></td>";
								echo "<td style=\"font-size: 10px; padding-top: 3px;\">".$authors_ranking[$i]->points."&nbsp;".POINTS."</td>";
								echo "<td align=\"right\" height=\"5px\">";
									echo "<a id=\"see-all-author-content-".$i."\" class=\"more\" href=\"publishedContent.php?user_id=".$authors_ranking[$i]->user_id."&first_name=".$authors_ranking[$i]->first_name."&last_name=".$authors_ranking[$i]->last_name."&coming_from=".$current_file."\">".SEE_ALL_HIS_CONTENT."</a>";
								echo "</td>";
							echo "</tr>";
						echo "</table>";
					echo "</div>";
				}
				?>
				
				<hr/>
				
				<div style="text-align: right; margin-top: 5px;">
					<a id="see-best-authors" class="more" href="bestAuthors.php?category_id=<?php echo $category_id; ?>&coming_from=<?php echo $current_file; ?>"><?php echo SEE_BEST_AUTHORS;?></a>
				</div>
				
			</div>
			<!-- End Col -->
			
			<div class="cl">&nbsp;</div>
			
		</div>
		<!-- End Cols -->
		
	</div>
</div>
<!-- End Main -->

<script>

	function resizeContentDownOptions() {
		var amountContentsDownOptions = <?php echo count($contents_ranking);?>;
		var content_max_heigth = <?php echo CONTENT_MAX_HEIGTH_DOWNOPTIONS;?>

		for (var i = 0; i < amountContentsDownOptions; i++) {
			wrapContentToHeight('down-option-content-td-' + i, content_max_heigth);
		}
	}

	resizeContentDownOptions();
</script>